using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json.Schema;
using ns20;

namespace ns21
{
	internal class Class126
	{
		private readonly JsonWriter jsonWriter_0;

		private readonly JsonSchemaResolver jsonSchemaResolver_0;

		[CompilerGenerated]
		private static Func<JsonSchemaType, bool> func_0;

		public Class126(JsonWriter writer, JsonSchemaResolver resolver)
		{
			Class204.smethod_2(writer, "writer");
			jsonWriter_0 = writer;
			jsonSchemaResolver_0 = resolver;
		}

		private void method_0(JsonSchema jsonSchema_0)
		{
			if (jsonSchema_0.Id != null && jsonSchemaResolver_0.GetSchema(jsonSchema_0.Id) != null)
			{
				jsonWriter_0.WriteStartObject();
				jsonWriter_0.WritePropertyName("$ref");
				jsonWriter_0.WriteValue(jsonSchema_0.Id);
				jsonWriter_0.WriteEndObject();
			}
			else
			{
				method_1(jsonSchema_0);
			}
		}

		public void method_1(JsonSchema jsonSchema_0)
		{
			Class204.smethod_2(jsonSchema_0, "schema");
			if (!jsonSchemaResolver_0.LoadedSchemas.Contains(jsonSchema_0))
			{
				jsonSchemaResolver_0.LoadedSchemas.Add(jsonSchema_0);
			}
			jsonWriter_0.WriteStartObject();
			method_5(jsonWriter_0, "id", jsonSchema_0.Id);
			method_5(jsonWriter_0, "title", jsonSchema_0.Title);
			method_5(jsonWriter_0, "description", jsonSchema_0.Description);
			method_5(jsonWriter_0, "required", jsonSchema_0.Required);
			method_5(jsonWriter_0, "readonly", jsonSchema_0.ReadOnly);
			method_5(jsonWriter_0, "hidden", jsonSchema_0.Hidden);
			method_5(jsonWriter_0, "transient", jsonSchema_0.Transient);
			if (jsonSchema_0.Type.HasValue)
			{
				method_4("type", jsonWriter_0, jsonSchema_0.Type.Value);
			}
			if (!jsonSchema_0.AllowAdditionalProperties)
			{
				jsonWriter_0.WritePropertyName("additionalProperties");
				jsonWriter_0.WriteValue(jsonSchema_0.AllowAdditionalProperties);
			}
			else if (jsonSchema_0.AdditionalProperties != null)
			{
				jsonWriter_0.WritePropertyName("additionalProperties");
				method_0(jsonSchema_0.AdditionalProperties);
			}
			if (!jsonSchema_0.AllowAdditionalItems)
			{
				jsonWriter_0.WritePropertyName("additionalItems");
				jsonWriter_0.WriteValue(jsonSchema_0.AllowAdditionalItems);
			}
			else if (jsonSchema_0.AdditionalItems != null)
			{
				jsonWriter_0.WritePropertyName("additionalItems");
				method_0(jsonSchema_0.AdditionalItems);
			}
			method_2(jsonWriter_0, "properties", jsonSchema_0.Properties);
			method_2(jsonWriter_0, "patternProperties", jsonSchema_0.PatternProperties);
			method_3(jsonSchema_0);
			method_5(jsonWriter_0, "minimum", jsonSchema_0.Minimum);
			method_5(jsonWriter_0, "maximum", jsonSchema_0.Maximum);
			method_5(jsonWriter_0, "exclusiveMinimum", jsonSchema_0.ExclusiveMinimum);
			method_5(jsonWriter_0, "exclusiveMaximum", jsonSchema_0.ExclusiveMaximum);
			method_5(jsonWriter_0, "minLength", jsonSchema_0.MinimumLength);
			method_5(jsonWriter_0, "maxLength", jsonSchema_0.MaximumLength);
			method_5(jsonWriter_0, "minItems", jsonSchema_0.MinimumItems);
			method_5(jsonWriter_0, "maxItems", jsonSchema_0.MaximumItems);
			method_5(jsonWriter_0, "divisibleBy", jsonSchema_0.DivisibleBy);
			method_5(jsonWriter_0, "format", jsonSchema_0.Format);
			method_5(jsonWriter_0, "pattern", jsonSchema_0.Pattern);
			if (jsonSchema_0.Enum != null)
			{
				jsonWriter_0.WritePropertyName("enum");
				jsonWriter_0.WriteStartArray();
				foreach (JToken item in jsonSchema_0.Enum)
				{
					item.WriteTo(jsonWriter_0);
				}
				jsonWriter_0.WriteEndArray();
			}
			if (jsonSchema_0.Default != null)
			{
				jsonWriter_0.WritePropertyName("default");
				jsonSchema_0.Default.WriteTo(jsonWriter_0);
			}
			if (jsonSchema_0.Disallow.HasValue)
			{
				method_4("disallow", jsonWriter_0, jsonSchema_0.Disallow.Value);
			}
			if (jsonSchema_0.Extends != null && jsonSchema_0.Extends.Count > 0)
			{
				jsonWriter_0.WritePropertyName("extends");
				if (jsonSchema_0.Extends.Count == 1)
				{
					method_0(jsonSchema_0.Extends[0]);
				}
				else
				{
					jsonWriter_0.WriteStartArray();
					foreach (JsonSchema extend in jsonSchema_0.Extends)
					{
						method_0(extend);
					}
					jsonWriter_0.WriteEndArray();
				}
			}
			jsonWriter_0.WriteEndObject();
		}

		private void method_2(JsonWriter jsonWriter_1, string string_0, IDictionary<string, JsonSchema> idictionary_0)
		{
			if (idictionary_0 == null)
			{
				return;
			}
			jsonWriter_1.WritePropertyName(string_0);
			jsonWriter_1.WriteStartObject();
			foreach (KeyValuePair<string, JsonSchema> item in idictionary_0)
			{
				jsonWriter_1.WritePropertyName(item.Key);
				method_0(item.Value);
			}
			jsonWriter_1.WriteEndObject();
		}

		private void method_3(JsonSchema jsonSchema_0)
		{
			if (jsonSchema_0.Items == null && !jsonSchema_0.PositionalItemsValidation)
			{
				return;
			}
			jsonWriter_0.WritePropertyName("items");
			if (!jsonSchema_0.PositionalItemsValidation)
			{
				if (jsonSchema_0.Items != null && jsonSchema_0.Items.Count > 0)
				{
					method_0(jsonSchema_0.Items[0]);
					return;
				}
				jsonWriter_0.WriteStartObject();
				jsonWriter_0.WriteEndObject();
				return;
			}
			jsonWriter_0.WriteStartArray();
			if (jsonSchema_0.Items != null)
			{
				foreach (JsonSchema item in jsonSchema_0.Items)
				{
					method_0(item);
				}
			}
			jsonWriter_0.WriteEndArray();
		}

		private void method_4(string string_0, JsonWriter jsonWriter_1, JsonSchemaType jsonSchemaType_0)
		{
			IList<JsonSchemaType> list2;
			if (Enum.IsDefined(typeof(JsonSchemaType), jsonSchemaType_0))
			{
				List<JsonSchemaType> list = new List<JsonSchemaType>();
				list.Add(jsonSchemaType_0);
				list2 = list;
			}
			else
			{
				list2 = (from jsonSchemaType_01 in Class187.smethod_0(jsonSchemaType_0)
					where jsonSchemaType_01 != JsonSchemaType.None
					select jsonSchemaType_01).ToList();
			}
			if (list2.Count == 0)
			{
				return;
			}
			jsonWriter_1.WritePropertyName(string_0);
			if (list2.Count == 1)
			{
				jsonWriter_1.WriteValue(Class131.smethod_1(list2[0]));
				return;
			}
			jsonWriter_1.WriteStartArray();
			foreach (JsonSchemaType item in list2)
			{
				jsonWriter_1.WriteValue(Class131.smethod_1(item));
			}
			jsonWriter_1.WriteEndArray();
		}

		private void method_5(JsonWriter jsonWriter_1, string string_0, object object_0)
		{
			if (object_0 != null)
			{
				jsonWriter_1.WritePropertyName(string_0);
				jsonWriter_1.WriteValue(object_0);
			}
		}

		[CompilerGenerated]
		private static bool smethod_0(JsonSchemaType jsonSchemaType_0)
		{
			return jsonSchemaType_0 != JsonSchemaType.None;
		}
	}
}
